package com.da.javatest.niuke.jianzhi;

/**
 * @author chenlida
 * @date 2020/10/22 16:26
 * https://www.nowcoder.com/practice/6aa9e04fc3794f68acf8778237ba065b?
 * tpId=13&tags=&title=&diffculty=0&judgeStatus=0&rp=1
 */
public class C33Solution {
    public int GetUglyNumber_Solution(int index) {
        if (index < 7) {
            return index;
        }
        int index2 = 0, index3 = 0, index5 = 0;
        int[] datas = new int[index];
        datas[0] = 1;
        for (int i = 1; i < index; i++) {
            datas[i] = Math.min(datas[index2] * 2, Math.min(datas[index3] * 3, datas[index5] * 5));
            if (datas[i] == datas[index2] * 2) {
                index2++;
            }
            if (datas[i] == datas[index3] * 3) {
                index3++;
            }
            if (datas[i] == datas[index5] * 5) {
                index5++;
            }
        }
        return datas[index - 1];
    }
}
